import { createStore } from 'vuex'
import { getCartList } from '../network/cart'
export default createStore({
  state: {
    cartCount: 0
  },
  mutations: {
    addCartCount(state, data) {
      state.cartCount = data.cartCount
    }
  },
  actions: {
    storeAddcart({ commit }) {
      if (window.localStorage.getItem('token')) {
        getCartList().then(res => {
          commit('addCartCount', { cartCount: res.data.length || 0 })
        })
      }
    }
  },
  modules: {}
})
